<template>
  <div class="log-page f-c">
    <div class="f-r j-b">
      <el-form inline>
        <el-form-item label="操作模块">
          <el-select v-model="searchParams.title" clearable placeholder="">
            <el-option v-for="item in titleList" :key="item" :label="item" :value="item" />
          </el-select>
        </el-form-item>
        <el-form-item label="时间">
          <el-date-picker v-model="searchParams.timeValue" placeholder="" />
        </el-form-item>
        <el-form-item label="操作人">
          <el-select v-model="searchParams.userId" clearable placeholder="">
            <el-option v-for="item in userList" :key="item.userId" :label="item.userName" :value="item.userId" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="margin-left: 15px" @click="onSearch">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-button plain type="primary" style="margin-bottom: 18px" @click="onExport">导出数据</el-button>
    </div>
    <div class="table-box">
      <el-table
        v-loading="loading"
        height="100%"
        stripe
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column type="index" align="center" label="序号" />
        <el-table-column prop="desc" label="操作名称" align="center" />
        <el-table-column prop="operatorType" label="操作类型" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.operatorType == 1" type="primary">后台用户</el-tag>
            <el-tag v-if="scope.row.operatorType == 2" type="success">手机端用户</el-tag>
            <el-tag v-if="scope.row.operatorType == 0" type="info">其它</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="operName" label="操作人" align="center" width="300px" />
        <el-table-column prop="operTime" label="操作时间" align="center" width="300px" />
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
  </div>
</template>

<script>
import crud from '@/mixins/crud';
import { http_log, http_user } from '@/api';
import { downloadFile } from '@/utils/download';
export default {
  name: 'Log',
  mixins: [crud],
  data() {
    return {
      request: http_log,
      searchParams: {
        timeValue: [],
        title: '',
        userId: ''
      },
      userList: [],
      titleList: []
    }
  },
  created() {
    // 获取操作人
    http_user.userName().then(res => {
      console.log(res)
      this.userList = res.rows
    })
    // 日志模块
    http_log.titleList().then(res => {
      console.log(res)
      this.titleList = res.rows.map(el => el.title)
    })
  },
  methods: {
    onExport() {
      http_log.export({
        ...this.getQueryParams(),
        pageNum: undefined,
        pageSize: undefined
      }).then(res => {
        console.log(res)
        downloadFile('日志.xls', res)
      })
    }
  }
}
</script>

<style scoped lang="scss">
.log-page {
  background-color: #fff;
  height: 100%;
  padding: 20px;
}
</style>
